unit testdataset;

{$mode objfpc}{$H+}

interface

uses
  Classes,
  SysUtils,
  fpcunit,
  common,
  testregistry,
  hadedataset,
  hadeconnectionmanager;

type

  { TTestDataSet }

  TTestDataSet = class(TTestCase)
  private
    FDataSet: THadeDataSet;
    con: THadeConnection;
  protected
    procedure SetUp; override;
    procedure TearDown; override;
  published
    procedure TestFetchData;
  end;

implementation

{ TTestDataSet }

procedure TTestDataSet.SetUp;
begin
  con := GHadeConnectionManager.ConnectionByName('test');
  FDataSet := THadeDataSet.Create(con);
end;

procedure TTestDataSet.TearDown;
begin
  GHadeConnectionManager.ReturnConnection(con);
  FreeAndNil(FDataSet);
end;

procedure TTestDataSet.TestFetchData;
var
  sql: string;
begin
  con.StartTransaction;
  sql := 'select * from person limit 1';
  FDataSet.SQL.Text := sql;
  FDataSet.Open;
  self.AssertTrue(FDataSet.Count > 0);
  self.AssertEquals('Fajar', FDataSet.StringByName['first_name']);
  FDataSet.Close;
  con.Commit;
end;

initialization
end.

